package com.nervenets.web.controller.handler.user.order;

import com.nervenets.web.controller.Global;
import com.nervenets.web.controller.handler.Handler;
import com.nervenets.web.controller.handler.common.IdTokenParams;
import com.nervenets.web.entity.MessageCode;
import com.nervenets.web.hibernate.domain.user.Order;

import javax.servlet.http.HttpServletRequest;

public class OrderDetailHandler extends Handler<IdTokenParams> {
    @Override
    public String handle(IdTokenParams params, HttpServletRequest request) throws Exception {
        final Order order = userDao.findById(params.getTargetId(), Order.class);
        if (null == order) return errorMessage(MessageCode.code_404, "订单不存在");

        Object union = null;
        switch (order.getOrderType()) {
            case movie:
                union = globalService.getMovie(order.getUnionId());
                break;
        }
        String orderNumber = Global.OrderNumber.getMBCreateNumber(order.getCreateTime(), order.getId());
        return successMessage(order, new KeyValue("union", union)
                , new KeyValue("orderNumber", orderNumber)
                , new KeyValue("salesOfMoney", globalService.getMovieBuyMoney(order.getUnionId()))
        );
    }

    @Override
    public String result() throws Exception {
        return successMessage("单个订单详情");
    }
}
